<include file="public@header_vue"/>

<script src="https://cdn.jsdelivr.net/npm/vue-ueditor-wrap@latest/lib/vue-ueditor-wrap.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/UEditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/UEditor/ueditor.all.min.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="__STATIC__/UEditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<div id="app">
    <el-card :header="role_id == 3 ? '分享规则设置' : '规则列表'" v-loading="onDataLoading" style="margin-bottom: 200px;">
        <div v-if="role_id != 3">
            <el-row>
                <el-col :span="20">
                    <el-form :inline="true" :model="searchForm" class="demo-form-inline" size="mini">
                        <el-form-item label="公司名称：">
                            <el-input v-model="searchForm.name" placeholder="公司名称"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="getData()">查询</el-button>
                            <el-button type="danger" @click="clearForm()">清空</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <el-table :data="tableData" style="width: 100%">

                <el-table-column prop="name" label="公司" min-width="120" show-overflow-tooltip></el-table-column>

                <el-table-column prop="company_name" label="会员卡激活送积分" min-width="200" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span>{{scope.row.options_list[0]['option_value']}}积分</span>
                    </template>
                </el-table-column>

                <el-table-column prop="account_name" label="购买产品得积分" min-width="150" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span>{{scope.row.options_list[1]['option_value']}}%</span>
                    </template>
                </el-table-column>

                <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" @click="edit(scope.row)">查看说明</el-button>
                    </template>
                </el-table-column>

            </el-table>
            <el-pagination background layout="total,prev, pager, next" :page-size="15" :total="totalNum" :current-page.sync="currentPage" @current-change="getData"></el-pagination>

            <el-dialog  title="查看" :visible.sync="dialogVisible" width="80%">
                <el-form :model="editForm" class="demo-form-inline" label-width="90px">
<!--                    <el-form-item label="公司名称" prop="name">-->
<!--                        <el-col :span="20">-->
<!--                            <el-input  v-model="editForm.name" placeholder="公司名称"></el-input>-->
<!--                        </el-col>-->
<!--                    </el-form-item>-->


                    <el-form-item label="奖励规则" prop="introduction">
                        <el-col :span="24">
                            <vue-ueditor-wrap v-model="introduction" :config="myConfig" style="line-height: 0px;"></vue-ueditor-wrap>
                        </el-col>
                    </el-form-item>

                </el-form>
            </el-dialog>


        </div>





        <el-form ref="form" :model="form" v-if="role_id == 3">

            <el-form-item label="推荐用户注册会员卡得积分数：">
                <el-col :span="8">
                    <el-input v-model="form.user_card_register" placeholder="推荐用户注册会员卡得积分" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
                </el-col>
                <el-button type="primary" @click="jxsSubmit()" style="margin-left: 40px;">保存</el-button>
            </el-form-item>

            <el-form-item label="推荐用户购买产品得积分比例：">
                <el-col :span="8">
                    <el-input v-model="form.user_buy" placeholder="推荐用户购买产品得积分比例" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
                </el-col>
                <el-button type="primary" @click="buySubmit()" style="margin-left: 40px;">保存</el-button>
            </el-form-item>


            <el-form-item label="分享奖励说明">
                <el-col :span="24">
                    <vue-ueditor-wrap v-model="form.sharing_of_rewards" :config="myConfig" style="line-height: 0px;"></vue-ueditor-wrap>
                </el-col>
            </el-form-item>
            <el-button type="primary" @click="infoSubmit()" style="margin-left: 40px;">保存</el-button>

        </el-form>


    </el-card>
</div>
</body>
<script>
    Vue.component('vue-ueditor-wrap', VueUeditorWrap);
    var app = new Vue({
        el: '#app',
        data: function () {
            return {
                role_id:'{$role_id}',
                tableData:[],
                totalNum:0,
                currentPage:1,
                myConfig: {
                    autoFloatEnabled:false,  //设置取消工具条浮动
                    // 编辑器不自动被内容撑高
                    autoHeightEnabled: false,
                    // 初始容器高度
                    initialFrameHeight: 600,
                    zIndex: 3000,
                    // 初始容器宽度
                    initialFrameWidth: '90%',
                    // 上传文件接口（这个地址是我为了方便各位体验文件上传功能搭建的临时接口，请勿在生产环境使用！！！）
                    serverUrl: 'http://fangtai.0513app.cn/static/UEditor/php/controller.php',
                    // UEditor 资源文件的存放路径，如果你使用的是 vue-cli 生成的项目，通常不需要设置该选项，vue-ueditor-wrap 会自动处理常见的情况，如果需要特殊配置，参考下方的常见问题2
                    UEDITOR_HOME_URL: '/static/UEditor/'
                },
                pickerOptions: {
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },

                form: {

                    user_card_register : {$user_card_register},//推荐用户注册会员卡得积分
                    user_buy : {$user_buy},//推荐用户购买产品得积分比例

                    sharing_of_rewards:'{$sharing_of_rewards}', // 分享奖励说明

                },
                options: [5, 10, 20, 30, 40, 50],
                onDataLoading:false,
                checkValue: '',
                searchForm:{
                    name:''
                },
                editForm:{},
                dialogVisible:false,
                introduction:''
            }
        },
        created () {
            this.getData();
        },
        methods: {

            clearForm () {
                console.log(this.searchForm);
                this.searchForm = {
                    name: '',
                }
            },

            checkKeydown(e, value){
                this.checkValue = value;
            },

            jxsSubmit() {

                let _this = this;
                this.onDataLoading = true;
                axios.post('/admin/Share/index', {user_card_register : this.form.user_card_register}, {
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                    }
                }).then(function (response) {
                    _this.onDataLoading = false;
                    if (response.data.code === 1) {
                        _this.$message.success('保存成功');
                        _this.onDataLoading = false;
                    } else {
                        _this.$message.warning(response.data.msg);
                    }
                }).catch(function (error) {
                    _this.dialogLoading = false;
                    _this.$message.error(error.toString())
                })
            },

            buySubmit() {

                let _this = this;
                this.onDataLoading = true;
                axios.post('/admin/Share/index', {user_buy : this.form.user_buy}, {
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                    }
                }).then(function (response) {
                    _this.onDataLoading = false;
                    if (response.data.code === 1) {
                        _this.$message.success('保存成功');
                        _this.onDataLoading = false;
                    } else {
                        _this.$message.warning(response.data.msg);
                    }
                }).catch(function (error) {
                    _this.dialogLoading = false;
                    _this.$message.error(error.toString())
                })
            },

            infoSubmit() {

                let _this = this;
                this.onDataLoading = true;
                axios.post('/admin/Share/index', {sharing_of_rewards : this.form.sharing_of_rewards}, {
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                    }
                }).then(function (response) {
                    _this.onDataLoading = false;
                    if (response.data.code === 1) {
                        _this.$message.success('保存成功');
                        _this.onDataLoading = false;
                    } else {
                        _this.$message.warning(response.data.msg);
                    }
                }).catch(function (error) {
                    _this.dialogLoading = false;
                    _this.$message.error(error.toString())
                })
            },


            getData (page = 1) {
                let _this = this;
                let params = {page: page};
                this.onDataLoading = true;
                if (this.searchForm.name !== '') {
                    params.name = this.searchForm.name;
                }

                console.log(params);

                axios.get('/admin/share/index', {
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                    },
                    params: params
                }).then(function (response) {
                    console.log(response);
                    _this.onDataLoading = false;
                    if (response.data.code === 1) {
                        _this.tableData = response.data.data.data;
                        _this.totalNum  = response.data.data.total;
                    } else {
                        _this.$message({
                            message: response.data.msg,
                            type: 'warning'
                        });
                    }
                }).catch(function (error) {
                    _this.onDataLoading = false;
                    _this.$message.error(error.toString())
                })
            },

            edit (row) {
                this.dialogVisible = true;
                if (row) {
                    this.editForm = JSON.parse(JSON.stringify(row));//深拷贝
                    this.introduction = this.editForm.options_list[2]['option_value'];
                }

            }

        }
    })
</script>
</html>
